<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>盒子水平居中</title>
    <style>
        .box1{
            width: 300px;
            height: 300px;
            border: 1px solid black;
            background-color: yellowgreen;
        }
        .box2{
            width: 200px;
            height: 200px;
            background-color: pink;
            margin:10px auto;
        }
        .box3{
            width: 300px;
            height: 300px;
            border: 1px solid black;
            background-color: red;
            padding: 100px ;
        }
        .box4{
            height: 200px;
            background-color: sandybrown;
            /* margin: 0 50px; */
            border: 1px solid;
        }
    </style>
</head>
<body>
    <div class="box1">
        <p>这是box1</p>
        <div class="box2">
            <p>这是box2</p>
        </div>
    </div>
    <div class="box3">
        <p>这是box3</p>
        <div class="box4">
            <p>
                这是box4
            </p>
        </div>
    </div>
    
</body>
</html>